#include "ActivityItem.h"

ActivityItem::ActivityItem(const QList<QVariant> &data, ActivityItem *parentItem)
{
    m_parentItem = parentItem;
    m_itemData = data;
}

ActivityItem::~ActivityItem()
{
    qDeleteAll(m_childItems);
}

void ActivityItem::appendChild(ActivityItem *child, int pos)
{
    this->m_childItems.insert (pos,child);
}

ActivityItem *ActivityItem::child(int row)
{
    return this->m_childItems.value (row);
}

int ActivityItem::childCount() const
{
    return this->m_childItems.count ();
}

int ActivityItem::columnCount() const
{
    return this->m_itemData.count ();
}

QVariant ActivityItem::data(int column) const
{
    return this->m_itemData.value (column);
}

void ActivityItem::setData(const QVariant &data, int column)
{
    if(column == -1) column = this->m_itemData.count ();
    this->m_itemData.insert(column==0?0:column-1,data);
}

int ActivityItem::row() const
{
    if(this->m_parentItem)
    {
        return this->m_parentItem->m_childItems.indexOf (const_cast<ActivityItem*>(this));
    }
    return 0;
}

ActivityItem *ActivityItem::parentItem()
{
    return this->m_parentItem;
}
